package com.qcc.nio.filter;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;

public class QccProxyBizFilter implements HttpRequestFilter {

    public static QccProxyBizFilter newInstance() {
        return new QccProxyBizFilter();
    }

    @Override
    public void filter(FullHttpRequest fullRequest, ChannelHandlerContext ctx) {
        String url = fullRequest.uri();
        if (url.startsWith("/testqcc")){
            System.out.println("请求放开");
        } else {
            throw new RuntimeException("url错误:" + url);
        }
        HttpHeaders headers = fullRequest.headers();
        if (headers == null) {
            headers = new DefaultHttpHeaders();
        }
        headers.add("proxy-tag", this.getClass().getSimpleName()+"_qcc");
    }
}
